{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Python Decorators"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "## function copy\n",
    "## closures\n",
    "## decorators"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "def welcome():\n",
    "    return \"Welcome to Krish Naik Youtube Channel\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [],
   "source": [
    "wel=welcome()\n",
    "del welcome"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Welcome to Krish Naik Youtube Channel'"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'welcome' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-56-a401d7101853>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mwelcome\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name 'welcome' is not defined"
     ]
    }
   ],
   "source": [
    "welcome()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Closures\n",
    "def main_welcome(msg):\n",
    "   \n",
    "    def sub_welcome_class():\n",
    "        print(\"Welcome To Krish Naik Youtube Channel\")\n",
    "        print(msg)\n",
    "        print(\"Please subscribe Krish channel\")\n",
    "    return sub_welcome_class()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Welcome To Krish Naik Youtube Channel\n",
      "Krish\n",
      "Please subscribe Krish channel\n"
     ]
    }
   ],
   "source": [
    "main_welcome(\"Krish\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Closures & initial Decorators\n",
    "def main_welcome(func):\n",
    "   \n",
    "    def sub_welcome_class():\n",
    "        print(\"Welcome To Krish Naik Youtube Channel\")\n",
    "        print(func([1,2,3,4,5,6]))\n",
    "        print(\"Please subscribe Krish channel\")\n",
    "    return sub_welcome_class()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Welcome To Krish Naik Youtube Channel\n",
      "6\n",
      "Please subscribe Krish channel\n"
     ]
    }
   ],
   "source": [
    "main_welcome(len)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Decorators\n",
    "def main_welcome(func):\n",
    "   \n",
    "    def sub_welcome_class():\n",
    "        print(\"Welcome To Krish Naik Youtube Channel\")\n",
    "        func()\n",
    "        print(\"Please subscribe Krish channel\")\n",
    "    return sub_welcome_class()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Welcome To Krish Naik Youtube Channel\n",
      "This is Krish youtube channel\n",
      "Please subscribe Krish channel\n"
     ]
    }
   ],
   "source": [
    "@main_welcome\n",
    "def channel_name():\n",
    "    print(\"This is Krish youtube channel\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Welcome To Krish Naik Youtube Channel\n",
      "This is Krish youtube channel\n",
      "Please subscribe Krish channel\n"
     ]
    }
   ],
   "source": [
    "a=main_welcome(channel_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
